package br.edu.ufabc.lnc.peanho.controller;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.SplashScreen;
import java.util.Properties;

import javax.swing.SwingUtilities;

import br.edu.ufabc.lnc.peanho.presenter.MainCanvasPresenter;
import br.edu.ufabc.lnc.peanho.util.Configuration;

public class Controller {

	public static void main(String[] args) {
		Controller.updateSplashScreen();
		Properties properties = Configuration.loadConfiguration();
		MainCanvasPresenter presenter = new MainCanvasPresenter(properties);
		presenter.createWindow();
		presenter.showWindow();
	}

	public static void updateSplashScreen() {
		Runnable runnable = new Runnable() {

			@Override
			public void run() {
				SplashScreen splashScreen = SplashScreen.getSplashScreen();
				if (splashScreen != null) {
					Dimension size = splashScreen.getSize();
					Graphics g = splashScreen.createGraphics();
					FontMetrics fontMetrics = g.getFontMetrics();
					int width = fontMetrics.stringWidth("Inicializando...");
					int height = fontMetrics.getHeight();
					g.setColor(Color.BLUE);
					g.drawString("Inicializando...", (size.width - width) / 2,
							(4 * height));
					splashScreen.update();
					
				}
			}
		};
		SwingUtilities.invokeLater(runnable);
	}
}
